
package com.interfacemodule.servlet;
import com.interfacemodule.bean.TbInterface;
import com.interfacemodule.dao.*;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import util.*;

public class TbInterfaceServlet extends HttpServlet{
    public void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        String method = request.getParameter("method")==null?"":request.getParameter("method");
        if("add".equals(method)){
        String interfaceCode=request.getParameter("interfaceCode");
        String interfaceName=request.getParameter("interfaceName");
        String interfactMemo=request.getParameter("interfactMemo");

            if(new TbInterfaceDAO().add(new TbInterface(interfaceCode,interfaceName,interfactMemo,new UtilDAO().decodeDate()))){
            request.getSession().setAttribute("result", "添加成功");
            }else{            
            request.getSession().setAttribute("result", "添加失败");
            }
             request.getSession(true).setAttribute("tbInterfaceList",new TbInterfaceDAO().getTbInterfaceAll());
            response.sendRedirect("InterfaceModule/TbInterfaceList.jsp");
        }
        if("del".equals(method)){
            if(UtilDAO.delin("Tb_Interface", "InterfaceId", request.getParameter("delIds"))){            
            request.getSession().setAttribute("result", "删除成功");
            }else{            
            request.getSession().setAttribute("result", "删除失败");
            }
             request.getSession(true).setAttribute("tbInterfaceList",new TbInterfaceDAO().getTbInterfaceAll());
            response.sendRedirect("InterfaceModule/TbInterfaceList.jsp");
        }
        if("edit".equals(method)){
        int interfaceId=Integer.parseInt(request.getParameter("interfaceId"));
        String interfaceCode=request.getParameter("interfaceCode");
        String interfaceName=request.getParameter("interfaceName");
        String interfactMemo=request.getParameter("interfactMemo");

            if(new TbInterfaceDAO().edit(new TbInterface(interfaceId,interfaceCode,interfaceName,interfactMemo,new UtilDAO().decodeDate()))){
            request.getSession().setAttribute("result", "修改成功");
            }else{            
            request.getSession().setAttribute("result", "修改失败");
            }
             request.getSession(true).setAttribute("tbInterfaceList",new TbInterfaceDAO().getTbInterfaceAll());
            response.sendRedirect("InterfaceModule/TbInterfaceList.jsp");
        }
        if ("list".equals(method)) {
             request.getSession(true).setAttribute("tbInterfaceList",new TbInterfaceDAO().getTbInterfaceAll());
            response.sendRedirect("InterfaceModule/TbInterfaceList.jsp");
        	}
        if ("listById".equals(method)) {
             request.getSession(true).setAttribute("tbInterface",new TbInterfaceDAO().getTbInterfaceByInterfaceId(Integer.parseInt(request.getParameter("interfaceId"))));
            response.sendRedirect("InterfaceModule/TbInterfaceOperate.jsp");
    	}
        if("showadd".equals(method)){
            request.removeAttribute("tbInterface");
            response.sendRedirect("InterfaceModule/TbInterfaceOperate.jsp");
        }
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }// end method doGet
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }// end method doPost
}
